cmake_minimum_required(VERSION 3.16)

project(WindowCapture VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找Qt6组件
find_package(Qt6 REQUIRED COMPONENTS 
    Core 
    Widgets 
    Network 
    Multimedia
)

# 设置源文件
set(SOURCES
    main.cpp
    mainwindow.cpp
    windowcapture.cpp
    websocketserver.cpp
    audiocapture.cpp
    application_manager.cpp
)

set(HEADERS
    mainwindow.h
    windowcapture.h
    websocketserver.h
    audiocapture.h
    application_manager.h
)

# 创建主程序
qt_add_executable(WindowCapture
    ${SOURCES}
    ${HEADERS}
)

# 链接Qt库
target_link_libraries(WindowCapture PRIVATE
    Qt6::Core
    Qt6::Widgets
    Qt6::Network
    Qt6::Multimedia
)

# 设置包含目录
target_include_directories(WindowCapture PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
)

# 启用Qt的MOC和RCC
set_target_properties(WindowCapture PROPERTIES
    AUTOMOC ON
    AUTORCC ON
)

# Windows特定设置
if(WIN32)
    # 链接Windows API库
    target_link_libraries(WindowCapture PRIVATE
        user32
        gdi32
        winmm
        ole32
        oleaut32
        uuid
        advapi32
        shell32
        version
        psapi
        kernel32
        d3d11
        dxgi
        windowsapp
    )
    
    # 设置为Windows应用程序
    set_target_properties(WindowCapture PROPERTIES
        WIN32_EXECUTABLE TRUE
    )
    
    # 添加Windows特定的编译定义
    target_compile_definitions(WindowCapture PRIVATE
        WIN32_LEAN_AND_MEAN
        NOMINMAX
        _WIN32_WINNT=0x0A00
    )
endif()

# 设置输出目录
set_target_properties(WindowCapture PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 安装规则
install(TARGETS WindowCapture
    RUNTIME DESTINATION bin
)
